#pragma once

#include <iostream>
#include <cstdlib>
#include <cerrno>
#include <unistd.h>
#include <fcntl.h>

void setNonBlock(int fd) 
{
    int fl = fcntl(fd, F_GETFL); //获取文件描述符打开时的标记位，O_CREAT|O_WRONLY|O_TRUNC
    if(fl < 0)
    {
        std::cerr << "fcntl error, fd: " << fd << std::endl;
        exit(0);
    }
    fcntl(fd, F_SETFL, fl | O_NONBLOCK); //加上非阻塞，O_CREAT|O_WRONLY|O_TRUNC|O_NONBLOCK
}